package com.hy.search.mq;

import com.hy.search.service.SearchService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ItemListener {

    @Autowired
    private SearchService searchService;

    /**
     * 监听新增和修改
     * @param spuId
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "search.item.insert.queue", durable = "true"),
            exchange = @Exchange(name = "xk.item.exchange",type = ExchangeTypes.TOPIC),
            key = {"item.insert","item.update"}))
    public void ListenerInsertOrUpdate(Long spuId){
        if (spuId==null){
            return;
        }
        //处理消息，对索引库进行新增或修改
        searchService.createOrUpdateIndex(spuId);
    }
    /**
     *TODO 监听删除
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "search.item.delete.queue", durable = "true"),
            exchange = @Exchange(name = "xk.item.exchange",type = ExchangeTypes.TOPIC),
            key = {"item.delete"}))
    public void ListenerDelete(Long spuId) {



    }


}
